# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import pymongo  # 默认27017


class BiliPipeline:
    def open_spider(self, spider):
        self.client = pymongo.MongoClient()  # 本机不用设置  都是默认即可

    def process_item(self, item, spider):
        """点第一个是库 点的第二个是表名"""
        self.client.bilibli.ranke.insert_one(item)
        return item

    def close_spider(self, spider):
        print("保存成功")
        self.client.close()
